/*
 * Created on Jun 2, 2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package org.scohen.juploadr.ui.thumbnail;

import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.MouseTrackListener;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.scohen.juploadr.app.ImageAttributes;

/**
 * @author steve
 * 
 * TODO To change the template for this generated type comment go to Window -
 * Preferences - Java - Code Style - Code Templates
 */
public abstract class AbstractThumbnailDecorator implements Thumbnail {
    protected Thumbnail thumb;
    protected ImageAttributes attrs;
    protected Composite parent;
   
    public AbstractThumbnailDecorator(Composite parent, ImageAttributes atts, Thumbnail t) {
        this.parent = parent;
        this.attrs = atts;
        this.thumb = t;
        t.addPaintListener(new PaintListener() {
            public void paintControl(PaintEvent event) {
                AbstractThumbnailDecorator.this.paintControl(event);
            }
        });
        t.addDisposeListener(new DisposeListener() {
            public void widgetDisposed(DisposeEvent e) {
                AbstractThumbnailDecorator.this.widgetDisposed(e);
            }

        });
    }

    abstract void paintControl(PaintEvent e);

    abstract void widgetDisposed(DisposeEvent e);

    public ImageAttributes getImageAttributes() {
        return attrs;
    }

    public void addMouseListener(MouseListener listener) {
        thumb.addMouseListener(listener);
    }

    public final void redraw() {
        if (!thumb.isDisposed()) {
            thumb.redraw();
        }
    }

    public final void dispose() {
        thumb.dispose();
    }

    public void setEnabled(boolean enabled) {
        thumb.setEnabled(enabled);
    }

    public final void addPaintListener(PaintListener listener) {
        thumb.addPaintListener(listener);
    }

    public final void addDisposeListener(DisposeListener listener) {
        thumb.addDisposeListener(listener);

    }

    public final void addMouseTrackListener(MouseTrackListener listener) {
        thumb.addMouseTrackListener(listener);
    }

    public final void addKeyListener(KeyListener listener) {
        thumb.addKeyListener(listener);
    }

    public Image getImage() {
        return thumb.getImage();
    }


    public boolean isDisposed() {
        return thumb.isDisposed();
    }

    public void thumbnailChanged() {
        thumb.thumbnailChanged();
    }

}